<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Products extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->model('products_m');
    }    
    
    public function index() {
        //open
        $temp = array();
        $temp['css'] = array('header','products');
        $temp['js'] = array('products');
        $this->load->view('open_v',$temp);
        //main
        $data['breadcumbs'] = $this->products_m->get_breadcumbs(0);
        $data['categories'] = $this->products_m->get_categories(0);
        $data['curr_cat'] = 0;
        $data['curr_parent_cat'] = 0;
        $data['products'] = $this->products_m->get_products_front($data['curr_cat']);
        $this->load->view('products/list_products_v',$data);
        //close
        $this->load->view('close_v');
    }
         
    public function next_page($curr_cat=null,$page=null){
        $data['products'] = $this->products_m->get_products_front($curr_cat,$page-1);
        $this->load->view('products/ajax_products_content',$data);
    }

    public function cat($cat_id,$cat_title=null){
        //open
        $temp = array();
        $temp['css'] = array('header','products');
        $temp['js'] = array('products');
        $this->load->view('open_v',$temp);
        //main
        $data['breadcumbs'] = $this->products_m->get_breadcumbs($cat_id);
        $data['curr_cat'] = $cat_id;
        $data['curr_parent_cat'] = $this->products_m->get_parent_cat($cat_id);
        $data['products'] = $this->products_m->get_products_front($data['curr_cat']);
        $this->load->view('products/list_products_v',$data);
        //close
        $this->load->view('close_v');
    }
    
    public function view($id){
        //open
        $temp = array();
        $temp['css'] = array('header','products');
        $temp['js'] = array('products');
        //main
        $data['product'] = $this->products_m->get_product_front($id);
        $temp['page_title'] = "Afteridea - ".$data['product']->name;
        $this->load->view('open_v',$temp);
        $this->load->view('products/product_v',$data);
        //close
        $this->load->view('close_v');
    }
}